//
//  IGLoginApi.m
//  jingdongfang
//
//  Created by BOE on 2017/8/9.
//  Copyright © 2017年 ZhiYu Hao. All rights reserved.
//

#import "IGLoginApi.h"

@implementation IGLoginApi

- (id)initWithLoginType:(IGLoginType)loginType {
    self = [super init];
    if (self) {
        _loginType = loginType;
    }
    return self;
}

- (NSString *)requestUrl {
    return [self customUrl];
}

- (BOOL)isNeedHub {
    return YES;
}

- (id)requestArgument {
    return [self customArg];
}

- (NSString *)customUrl {
    if (self.loginType == IGLoginTypeNormal) {
        return @"member/login";
    } else {
        return @"member/oauthReg";
    }
}

- (BOOL)isHttps {
    if (self.loginType == IGLoginTypeNormal) {
        return YES;
    } else {
        return NO;
    }
}

- (id)customArg {
    if (self.loginType == IGLoginTypeNormal) {
        return @{
                 @"phoneNo": _username,
                 @"password": _password
                 };
    } else {
        return @{
                 @"loginPlat": [self loginPlatStr],
                 @"clientType": [self clientTypeStr],
                 @"openId":_openId==nil?@"":_openId,
                 @"accessToken":_accessToken==nil?@"":_accessToken,
                 @"nike":_nike==nil?@"":_nike,
                 @"image":_image==nil?@"":_image
                 };
    }
}

- (NSString *)loginPlatStr {
    switch (self.loginPlat) {
        case IGTloginPlatTypewx:
            return @"wx";
            break;
        case IGTloginPlatTypeqq:
            return @"qq";
            break;
        case IGTloginPlatTypeweibo:
            return @"weibo";
            break;
        default:
            break;
    }
}

- (NSString *)clientTypeStr {
    switch (self.clientType) {
        case IGTClientTypeweb:
            return @"web";
            break;
        case IGTClientTypewap:
            return @"wap";
            break;
        case IGTClientTypeapp:
            return @"app";
            break;
        default:
            break;
    }
}

@end

@implementation IGLoginModel

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
    return YES;
}

+ (JSONKeyMapper *)keyMapper
    {
        return [[JSONKeyMapper alloc]
                initWithModelToJSONDictionary:@{
                                                @"userinfo":@"member"
                                                }];
    }
    
@end

@implementation IGLoginResp

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
    return YES;
}
    
@end
